package com.dynamixsoftware.printershare;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Resources;
import android.database.DataSetObserver;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.DisplayMetrics;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.dynamixsoftware.printershare.data.XmlUtil;
import com.google.android.googleapps.GoogleLoginCredentialsResult;
import com.google.android.googleapps.IGoogleLoginService;
import com.google.android.googleapps.IGoogleLoginService.Stub;
import com.google.android.googlelogin.GoogleLoginServiceConstants;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Vector;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class ActivityGDocsBrowser
  extends ActivityRoot
{
  private static int requesting_credentials;
  private FolderAdapter adapter;
  private String[] al;
  private Object[] al_objs;
  private String[] credentials;
  private volatile Vector<Entry> data;
  boolean ftoken;
  private Handler handler;
  private ListView list;
  private Thread wt;
  
  private void authorize(String paramString)
  {
    this.credentials = new String[3];
    this.credentials[0] = paramString;
    this.data.clear();
    Runnable local6 = new Runnable()
    {
      public void run()
      {
        ActivityGDocsBrowser.this.adapter.changeFolder(null);
      }
    };
    runOnUiThread(local6);
    Object localObject1;
    if (App.has_feature_gls)
    {
      localObject1 = getSystemService("account");
      if (localObject1 == null) {}
    }
    for (;;)
    {
      int n;
      int k;
      Bundle localBundle2;
      try
      {
        Object[] arrayOfObject1 = this.al_objs;
        int j = 0;
        if (arrayOfObject1 != null)
        {
          n = 0;
          int i1 = this.al.length;
          j = 0;
          if (n < i1)
          {
            if (!this.al[n].equals(paramString)) {
              break label962;
            }
            j = n;
          }
        }
        Method[] arrayOfMethod = localObject1.getClass().getMethods();
        k = 0;
        int m = arrayOfMethod.length;
        Method localMethod = null;
        if (k < m)
        {
          if ((!"getAuthToken".equals(arrayOfMethod[k].getName())) || (arrayOfMethod[k].getParameterTypes().length != 5)) {
            break label968;
          }
          localMethod = arrayOfMethod[k];
        }
        Object[] arrayOfObject2 = new Object[5];
        arrayOfObject2[0] = this.al_objs[j];
        arrayOfObject2[1] = "writely";
        arrayOfObject2[2] = Boolean.valueOf(false);
        arrayOfObject2[3] = null;
        arrayOfObject2[4] = this.handler;
        Object localObject2 = localMethod.invoke(localObject1, arrayOfObject2);
        Bundle localBundle1 = (Bundle)localObject2.getClass().getMethod("getResult", new Class[0]).invoke(localObject2, new Object[0]);
        Intent localIntent2 = (Intent)localBundle1.getParcelable("intent");
        if (localIntent2 != null)
        {
          if (requesting_credentials == 0)
          {
            requesting_credentials = 1;
            startActivity(localIntent2);
            this.wt = null;
          }
        }
        else
        {
          this.credentials[1] = localBundle1.getString("authtoken");
          if (requesting_credentials == 1) {
            requesting_credentials = 0;
          }
        }
        Object[] arrayOfObject3 = new Object[5];
        arrayOfObject3[0] = this.al_objs[j];
        arrayOfObject3[1] = "wise";
        arrayOfObject3[2] = Boolean.valueOf(false);
        arrayOfObject3[3] = null;
        arrayOfObject3[4] = this.handler;
        Object localObject3 = localMethod.invoke(localObject1, arrayOfObject3);
        localBundle2 = (Bundle)localObject3.getClass().getMethod("getResult", new Class[0]).invoke(localObject3, new Object[0]);
        Intent localIntent3 = (Intent)localBundle2.getParcelable("intent");
        if (localIntent3 != null) {
          if (requesting_credentials == 0)
          {
            requesting_credentials = 2;
            startActivity(localIntent3);
            this.wt = null;
            return;
          }
        }
      }
      catch (Exception localException3)
      {
        localException3.printStackTrace();
        App.reportThrowable(localException3);
      }
      for (;;)
      {
        requesting_credentials = 0;
        authorize_done();
        return;
        this.credentials[2] = localBundle2.getString("authtoken");
        if (requesting_credentials == 2) {
          requesting_credentials = 0;
        }
      }
      Intent localIntent1 = GoogleLoginServiceConstants.SERVICE_INTENT;
      ServiceConnection local7 = new ServiceConnection()
      {
        public void onServiceConnected(ComponentName paramAnonymousComponentName, IBinder paramAnonymousIBinder)
        {
          IGoogleLoginService localIGoogleLoginService = IGoogleLoginService.Stub.asInterface(paramAnonymousIBinder);
          try
          {
            ActivityGDocsBrowser.this.credentials[1] = localIGoogleLoginService.peekCredentials(ActivityGDocsBrowser.this.credentials[0], "writely");
            if (ActivityGDocsBrowser.this.credentials[1] == null)
            {
              GoogleLoginCredentialsResult localGoogleLoginCredentialsResult2 = localIGoogleLoginService.blockingGetCredentials(ActivityGDocsBrowser.this.credentials[0], "writely", false);
              ActivityGDocsBrowser.this.credentials[1] = localGoogleLoginCredentialsResult2.getCredentialsString();
            }
            ActivityGDocsBrowser.this.credentials[2] = localIGoogleLoginService.peekCredentials(ActivityGDocsBrowser.this.credentials[0], "wise");
            if (ActivityGDocsBrowser.this.credentials[2] == null)
            {
              GoogleLoginCredentialsResult localGoogleLoginCredentialsResult1 = localIGoogleLoginService.blockingGetCredentials(ActivityGDocsBrowser.this.credentials[0], "wise", false);
              ActivityGDocsBrowser.this.credentials[2] = localGoogleLoginCredentialsResult1.getCredentialsString();
            }
          }
          catch (Exception localException)
          {
            for (;;)
            {
              localException.printStackTrace();
              App.reportThrowable(localException);
            }
          }
          ActivityGDocsBrowser.this.authorize_done();
          ActivityGDocsBrowser.this.unbindService(this);
        }
        
        public void onServiceDisconnected(ComponentName paramAnonymousComponentName) {}
      };
      if (!bindService(localIntent1, local7, 1))
      {
        authorize_done();
        return;
        try
        {
          if (this.credentials[0] != null)
          {
            int i = this.credentials[0].indexOf("");
            if (i > 0)
            {
              str1 = this.credentials[0].substring(i + 1);
              this.credentials[0] = this.credentials[0].substring(0, i);
              String str2 = App.glsGetAuthToken("writely", this.credentials[0], str1);
              String str3 = App.glsGetAuthToken("wise", this.credentials[0], str1);
              if ((str2 != null) && (str3 != null))
              {
                localEditor = this.prefs.edit();
                localEditor.putString("gdocs_token1_" + this.credentials[0], str2);
                localEditor.putString("gdocs_token2_" + this.credentials[0], str3);
              }
            }
          }
        }
        catch (Exception localException1)
        {
          String str1;
          SharedPreferences.Editor localEditor;
          String str4;
          String str5;
          label809:
          Runnable local8;
          localException1.printStackTrace();
          App.reportThrowable(localException1);
          authorize_done();
          return;
        }
        try
        {
          str4 = App.glsGetAuthToken("mail", this.credentials[0], str1);
          if (str4 != null) {
            localEditor.putString("gmail_token_" + this.credentials[0], str4);
          }
          str5 = App.glsGetAuthToken("cloudprint", this.credentials[0], str1);
          if (str5 != null) {
            localEditor.putString("cloud_token_" + this.credentials[0], str5);
          }
        }
        catch (Exception localException2)
        {
          localException2.printStackTrace();
          App.reportThrowable(localException2);
          break label809;
        }
        localEditor.commit();
        this.credentials[1] = this.prefs.getString("gdocs_token1_" + this.credentials[0], null);
        this.credentials[2] = this.prefs.getString("gdocs_token2_" + this.credentials[0], null);
        if ((this.credentials[1] == null) || (this.credentials[2] == null))
        {
          local8 = new Runnable()
          {
            public void run()
            {
              ActivityGDocsBrowser.this.hideProgress();
              final View localView = LayoutInflater.from(ActivityGDocsBrowser.this).inflate(2130903045, null);
              localView.findViewById(2131230742).setVisibility(0);
              EditText localEditText = (EditText)localView.findViewById(2131230739);
              localEditText.setText(ActivityGDocsBrowser.this.credentials[0]);
              if (ActivityGDocsBrowser.this.prefs.getString("gdocs_account", null) != null)
              {
                localEditText.setInputType(0);
                localEditText.setFocusable(false);
              }
              new AlertDialog.Builder(ActivityGDocsBrowser.this).setIcon(17301543).setTitle(2131099841).setView(localView).setCancelable(false).setPositiveButton(2131099703, new DialogInterface.OnClickListener()
              {
                public void onClick(DialogInterface paramAnonymous2DialogInterface, int paramAnonymous2Int)
                {
                  final String str1 = ((EditText)localView.findViewById(2131230739)).getText().toString();
                  final String str2 = ((EditText)localView.findViewById(2131230741)).getText().toString();
                  ActivityGDocsBrowser.this.showProgress(ActivityGDocsBrowser.this.getResources().getString(2131099746));
                  new Thread()
                  {
                    public void run()
                    {
                      ActivityGDocsBrowser.this.authorize(str1 + "" + str2);
                    }
                  }.start();
                }
              }).setNegativeButton(2131099707, new DialogInterface.OnClickListener()
              {
                public void onClick(DialogInterface paramAnonymous2DialogInterface, int paramAnonymous2Int)
                {
                  ActivityGDocsBrowser.this.authorize_done();
                }
              }).create().show();
            }
          };
          runOnUiThread(local8);
          return;
        }
      }
      return;
      label962:
      n++;
      continue;
      label968:
      k++;
    }
  }
  
  private void authorize_done()
  {
    this.last_error = null;
    if ((this.credentials[1] != null) && (this.credentials[2] != null))
    {
      if (this.prefs.getString("gdocs_account", null) == null) {}
      for (int i = 1;; i++)
      {
        String str = this.prefs.getString("gls_account_" + i, null);
        if ((str == null) || (str.equals(this.credentials[0])))
        {
          SharedPreferences.Editor localEditor = this.prefs.edit();
          localEditor.putString("gls_account_" + i, this.credentials[0]);
          localEditor.putString("gdocs_account", this.credentials[0]);
          localEditor.commit();
          if ((loadFolder("root")) || (this.last_error != null)) {
            break;
          }
          return;
        }
      }
    }
    this.last_error = "Error: Authorization failed or network error has occured";
    this.wt = null;
    runOnUiThread(new Runnable()
    {
      public void run()
      {
        ActivityGDocsBrowser.this.adapter.changeFolder(null);
        ActivityGDocsBrowser.this.hideProgress();
        if (ActivityGDocsBrowser.this.last_error != null) {
          ActivityGDocsBrowser.this.displayLastError(new DialogInterface.OnClickListener()
          {
            public void onClick(DialogInterface paramAnonymous2DialogInterface, int paramAnonymous2Int)
            {
              if (!ActivityGDocsBrowser.this.isFinishing()) {
                ActivityGDocsBrowser.this.list.showContextMenu();
              }
            }
          });
        }
      }
    });
  }
  
  private void init()
  {
    try
    {
      Thread.sleep(500L);
      label6:
      if (App.has_feature_gls)
      {
        Object localObject = getSystemService("account");
        if (localObject != null) {
          try
          {
            Object[] arrayOfObject = (Object[])localObject.getClass().getMethod("getAccountsByType", new Class[] { String.class }).invoke(localObject, new Object[] { "com.google" });
            this.al_objs = arrayOfObject;
            if (arrayOfObject != null)
            {
              this.al = new String[arrayOfObject.length];
              if (arrayOfObject.length > 0)
              {
                Field localField = arrayOfObject[0].getClass().getField("name");
                for (int j = 0; j < arrayOfObject.length; j++) {
                  this.al[j] = ((String)localField.get(arrayOfObject[j]));
                }
              }
            }
            return;
          }
          catch (Exception localException)
          {
            localException.printStackTrace();
            App.reportThrowable(localException);
            init_done();
          }
        }
        while (bindService(GoogleLoginServiceConstants.SERVICE_INTENT, new ServiceConnection()
        {
          public void onServiceConnected(ComponentName paramAnonymousComponentName, IBinder paramAnonymousIBinder)
          {
            IGoogleLoginService localIGoogleLoginService = IGoogleLoginService.Stub.asInterface(paramAnonymousIBinder);
            try
            {
              ActivityGDocsBrowser.access$402(ActivityGDocsBrowser.this, localIGoogleLoginService.getAccounts());
              ActivityGDocsBrowser.this.init_done();
              ActivityGDocsBrowser.this.unbindService(this);
              return;
            }
            catch (RemoteException localRemoteException)
            {
              for (;;)
              {
                localRemoteException.printStackTrace();
                App.reportThrowable(localRemoteException);
              }
            }
          }
          
          public void onServiceDisconnected(ComponentName paramAnonymousComponentName) {}
        }, 1)) {}
        init_done();
        return;
      }
      Vector localVector = new Vector();
      for (int i = 1;; i++)
      {
        String str = this.prefs.getString("gls_account_" + i, null);
        if (str == null) {
          break;
        }
        localVector.add(str);
      }
      this.al = ((String[])localVector.toArray(new String[0]));
      init_done();
      return;
    }
    catch (InterruptedException localInterruptedException)
    {
      break label6;
    }
  }
  
  private void init_done()
  {
    this.wt = null;
    runOnUiThread(new Runnable()
    {
      public void run()
      {
        String str1 = ActivityGDocsBrowser.this.prefs.getString("gdocs_account", null);
        String[] arrayOfString = ActivityGDocsBrowser.this.al;
        String str2 = null;
        int j;
        if (arrayOfString != null)
        {
          int i = ActivityGDocsBrowser.this.al.length;
          str2 = null;
          if (i > 0)
          {
            j = 0;
            int k = ActivityGDocsBrowser.this.al.length;
            str2 = null;
            if (j < k)
            {
              if (!ActivityGDocsBrowser.this.al[j].equals(str1)) {
                break label101;
              }
              str2 = str1;
            }
          }
        }
        if (str2 != null) {
          ActivityGDocsBrowser.this.showAccount(str2);
        }
        label101:
        do
        {
          return;
          j++;
          break;
          ActivityGDocsBrowser.this.hideProgress();
        } while (ActivityGDocsBrowser.this.isFinishing());
        ActivityGDocsBrowser.this.list.showContextMenu();
      }
    });
  }
  
  private boolean loadFolder(String paramString)
  {
    this.last_error = null;
    try
    {
      BasicHttpParams localBasicHttpParams = new BasicHttpParams();
      HttpConnectionParams.setConnectionTimeout(localBasicHttpParams, 15000);
      HttpConnectionParams.setSoTimeout(localBasicHttpParams, 15000);
      DefaultHttpClient localDefaultHttpClient = new DefaultHttpClient(localBasicHttpParams);
      HttpGet localHttpGet = new HttpGet("https://docs.google.com/feeds/default/private/full/folder:" + paramString + "/contents?showfolders=true");
      localHttpGet.setHeader("User-Agent", App.getUserAgent());
      localHttpGet.setHeader("Authorization", "GoogleLogin auth=" + this.credentials[1]);
      localHttpGet.setHeader("GData-Version", "3.0");
      HttpResponse localHttpResponse = localDefaultHttpClient.execute(localHttpGet);
      StatusLine localStatusLine = localHttpResponse.getStatusLine();
      if (localStatusLine.getStatusCode() == 200)
      {
        NodeList localNodeList = XmlUtil.getDocument(localHttpResponse.getEntity().getContent()).getDocumentElement().getElementsByTagName("entry");
        int k = localNodeList.getLength();
        for (int m = 0; m < k; m++)
        {
          Entry localEntry = new Entry((Element)localNodeList.item(m));
          this.data.add(localEntry);
        }
      }
      if (((localStatusLine.getStatusCode() == 401) || ("Token expired".equalsIgnoreCase(localStatusLine.getReasonPhrase()))) && (!this.ftoken))
      {
        this.ftoken = true;
        if (App.has_feature_gls)
        {
          Object localObject = getSystemService("account");
          if (localObject != null)
          {
            try
            {
              Method[] arrayOfMethod = localObject.getClass().getMethods();
              for (int i = 0;; i++)
              {
                int j = arrayOfMethod.length;
                Method localMethod = null;
                if (i < j)
                {
                  if (("invalidateAuthToken".equals(arrayOfMethod[i].getName())) && (arrayOfMethod[i].getParameterTypes().length == 2)) {
                    localMethod = arrayOfMethod[i];
                  }
                }
                else
                {
                  Object[] arrayOfObject1 = new Object[2];
                  arrayOfObject1[0] = "com.google";
                  arrayOfObject1[1] = this.credentials[1];
                  localMethod.invoke(localObject, arrayOfObject1);
                  Object[] arrayOfObject2 = new Object[2];
                  arrayOfObject2[0] = "com.google";
                  arrayOfObject2[1] = this.credentials[2];
                  localMethod.invoke(localObject, arrayOfObject2);
                  authorize(this.credentials[0]);
                  return false;
                }
              }
              localIntent = GoogleLoginServiceConstants.SERVICE_INTENT;
            }
            catch (Exception localException2)
            {
              localException2.printStackTrace();
              App.reportThrowable(localException2);
            }
          }
          else
          {
            Intent localIntent;
            ServiceConnection local10 = new ServiceConnection()
            {
              public void onServiceConnected(ComponentName paramAnonymousComponentName, IBinder paramAnonymousIBinder)
              {
                IGoogleLoginService localIGoogleLoginService = IGoogleLoginService.Stub.asInterface(paramAnonymousIBinder);
                try
                {
                  localIGoogleLoginService.invalidateAuthToken(ActivityGDocsBrowser.this.credentials[1]);
                  localIGoogleLoginService.invalidateAuthToken(ActivityGDocsBrowser.this.credentials[2]);
                  ActivityGDocsBrowser.this.unbindService(this);
                  ActivityGDocsBrowser.access$202(ActivityGDocsBrowser.this, new Thread()
                  {
                    public void run()
                    {
                      ActivityGDocsBrowser.this.authorize(ActivityGDocsBrowser.this.credentials[0]);
                    }
                  });
                  ActivityGDocsBrowser.this.wt.start();
                  return;
                }
                catch (Exception localException)
                {
                  for (;;)
                  {
                    localException.printStackTrace();
                    App.reportThrowable(localException);
                  }
                }
              }
              
              public void onServiceDisconnected(ComponentName paramAnonymousComponentName) {}
            };
            if (bindService(localIntent, local10, 1)) {
              return false;
            }
          }
        }
        else
        {
          SharedPreferences.Editor localEditor = this.prefs.edit();
          localEditor.putString("gdocs_token1_" + this.credentials[0], null);
          localEditor.putString("gdocs_token2_" + this.credentials[0], null);
          localEditor.commit();
          authorize(this.credentials[0]);
          return false;
        }
      }
      else
      {
        this.last_error = ("Error: HTTP error " + localStatusLine.getStatusCode() + ". " + localStatusLine.getReasonPhrase());
      }
    }
    catch (Exception localException1)
    {
      this.last_error = ("Internal Error: " + localException1.getMessage());
      localException1.printStackTrace();
      App.reportThrowable(localException1);
    }
    return true;
    return false;
  }
  
  private void showAccount(final String paramString)
  {
    showProgress(getResources().getString(2131099746));
    SharedPreferences.Editor localEditor = this.prefs.edit();
    localEditor.putString("gdocs_account", paramString);
    localEditor.commit();
    this.wt = new Thread()
    {
      public void run()
      {
        ActivityGDocsBrowser.this.authorize(paramString);
      }
    };
    this.wt.start();
  }
  
  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    this.data = new Vector();
    this.handler = new Handler();
    float f = getResources().getDisplayMetrics().density;
    this.list = new ListView(this);
    this.list.setPadding(0, (int)(5.0F * f), 0, 0);
    this.list.setCacheColorHint(0);
    this.list.setOnCreateContextMenuListener(this);
    this.list.setOnItemClickListener(new AdapterView.OnItemClickListener()
    {
      public void onItemClick(AdapterView<?> paramAnonymousAdapterView, View paramAnonymousView, int paramAnonymousInt, long paramAnonymousLong)
      {
        int i = ((Integer)paramAnonymousView.getTag()).intValue();
        final ActivityGDocsBrowser.Entry localEntry1 = (ActivityGDocsBrowser.Entry)ActivityGDocsBrowser.this.adapter.getItem(i);
        if ("folder".equals(localEntry1.type))
        {
          if (!"".equals(localEntry1.id))
          {
            ActivityGDocsBrowser.this.adapter.changeFolder(localEntry1);
            return;
          }
          ActivityGDocsBrowser.FolderAdapter localFolderAdapter = ActivityGDocsBrowser.this.adapter;
          if (ActivityGDocsBrowser.FolderAdapter.access$100(ActivityGDocsBrowser.this.adapter).size() > 1) {}
          for (ActivityGDocsBrowser.Entry localEntry2 = (ActivityGDocsBrowser.Entry)ActivityGDocsBrowser.FolderAdapter.access$100(ActivityGDocsBrowser.this.adapter).get(-2 + ActivityGDocsBrowser.FolderAdapter.access$100(ActivityGDocsBrowser.this.adapter).size());; localEntry2 = null)
          {
            localFolderAdapter.changeFolder(localEntry2);
            return;
          }
        }
        ActivityGDocsBrowser.this.showProgress(ActivityGDocsBrowser.this.getResources().getString(2131099757));
        ActivityGDocsBrowser.access$202(ActivityGDocsBrowser.this, new Thread()
        {
          public void run()
          {
            ActivityGDocsBrowser.this.last_error = null;
            for (;;)
            {
              StatusLine localStatusLine;
              File localFile;
              FileOutputStream localFileOutputStream;
              try
              {
                BasicHttpParams localBasicHttpParams = new BasicHttpParams();
                HttpConnectionParams.setConnectionTimeout(localBasicHttpParams, 15000);
                HttpConnectionParams.setSoTimeout(localBasicHttpParams, 15000);
                DefaultHttpClient localDefaultHttpClient = new DefaultHttpClient(localBasicHttpParams);
                HttpGet localHttpGet = new HttpGet(localEntry1.url);
                localHttpGet.setHeader("User-Agent", App.getUserAgent());
                if (localEntry1.url.indexOf("spreadsheets") >= 0)
                {
                  localHttpGet.setHeader("Authorization", "GoogleLogin auth=" + ActivityGDocsBrowser.this.credentials[2]);
                  localHttpGet.setHeader("GData-Version", "3.0");
                  HttpResponse localHttpResponse = localDefaultHttpClient.execute(localHttpGet);
                  localStatusLine = localHttpResponse.getStatusLine();
                  if (localStatusLine.getStatusCode() != 200) {
                    break label676;
                  }
                  HttpEntity localHttpEntity = localHttpResponse.getEntity();
                  Header localHeader = localHttpEntity.getContentType();
                  if (localHeader == null) {
                    break label731;
                  }
                  str = localHeader.getValue();
                  int i = (int)localHttpEntity.getContentLength();
                  localFile = new File(App.getTempDir(), "printershare_doc.tmp");
                  localFileOutputStream = new FileOutputStream(localFile);
                  InputStream localInputStream = localHttpEntity.getContent();
                  byte[] arrayOfByte = new byte[4096];
                  int j = 0;
                  int k = 0;
                  int m = localInputStream.read(arrayOfByte);
                  if (m == -1) {
                    break label459;
                  }
                  localFileOutputStream.write(arrayOfByte, 0, m);
                  j += m;
                  if (i <= 0) {
                    continue;
                  }
                  final int n = j * 100 / i;
                  if (n <= k) {
                    continue;
                  }
                  k = n;
                  ActivityGDocsBrowser localActivityGDocsBrowser2 = ActivityGDocsBrowser.this;
                  Runnable local1 = new Runnable()
                  {
                    public void run()
                    {
                      ActivityGDocsBrowser localActivityGDocsBrowser = ActivityGDocsBrowser.this;
                      String str = ActivityGDocsBrowser.this.getResources().getString(2131099758);
                      Object[] arrayOfObject = new Object[1];
                      arrayOfObject[0] = (n + "%");
                      localActivityGDocsBrowser.showProgress(String.format(str, arrayOfObject));
                    }
                  };
                  localActivityGDocsBrowser2.runOnUiThread(local1);
                  continue;
                }
                ActivityGDocsBrowser localActivityGDocsBrowser1;
                Runnable local2;
                localHttpGet.setHeader("Authorization", "GoogleLogin auth=" + ActivityGDocsBrowser.this.credentials[1]);
              }
              catch (Exception localException)
              {
                localException.printStackTrace();
                ActivityGDocsBrowser.this.last_error = ("Internal Error: " + localException.getMessage());
                App.reportThrowable(localException);
                ActivityGDocsBrowser.access$202(ActivityGDocsBrowser.this, null);
                localActivityGDocsBrowser1 = ActivityGDocsBrowser.this;
                local2 = new Runnable()
                {
                  public void run()
                  {
                    ActivityGDocsBrowser.this.hideProgress();
                    if (ActivityGDocsBrowser.this.last_error != null) {
                      ActivityGDocsBrowser.this.displayLastError(new DialogInterface.OnClickListener()
                      {
                        public void onClick(DialogInterface paramAnonymous4DialogInterface, int paramAnonymous4Int) {}
                      });
                    }
                  }
                };
                localActivityGDocsBrowser1.runOnUiThread(local2);
                return;
              }
              continue;
              label459:
              localFileOutputStream.close();
              Intent localIntent = new Intent("android.intent.action.VIEW");
              int i1 = str.indexOf(";");
              if (i1 > 0) {
                str = str.substring(0, i1);
              }
              if (str.startsWith("image/")) {
                localIntent.setClass(ActivityGDocsBrowser.this, ActivityPrintPictures.class);
              }
              for (;;)
              {
                localIntent.setDataAndType(Uri.parse("file://" + localFile.getAbsolutePath()), str);
                if (localFile.length() <= 0L) {
                  break label660;
                }
                ActivityGDocsBrowser.this.startActivity(localIntent);
                break;
                if (str.equals("text/html")) {
                  localIntent.setClass(ActivityGDocsBrowser.this, ActivityPrintWeb.class);
                } else if (str.equals("application/pdf")) {
                  localIntent.setClass(ActivityGDocsBrowser.this, ActivityPrintPDF.class);
                } else {
                  localIntent.setClass(ActivityGDocsBrowser.this, ActivityPrintDocuments.class);
                }
              }
              label660:
              ActivityGDocsBrowser.this.last_error = "Error: Can't load document. Content-Length=0.";
              continue;
              label676:
              ActivityGDocsBrowser.this.last_error = ("Error: HTTP error " + localStatusLine.getStatusCode() + ". " + localStatusLine.getReasonPhrase());
              continue;
              label731:
              String str = null;
            }
          }
        });
        ActivityGDocsBrowser.this.wt.start();
      }
    });
    setContentView(this.list);
    setTitle(2131099701);
    this.adapter = new FolderAdapter();
    this.list.setAdapter(this.adapter);
    this.ftoken = false;
    showProgress(getResources().getString(2131099746));
  }
  
  public void onCreateContextMenu(ContextMenu paramContextMenu, View paramView, ContextMenu.ContextMenuInfo paramContextMenuInfo)
  {
    paramContextMenu.setHeaderTitle(getResources().getString(2131099664));
    if (this.al != null) {
      for (int i = 0; i < this.al.length; i++) {
        paramContextMenu.add(0, i + 1000, 0, this.al[i]);
      }
    }
    if ((!App.has_feature_gls) || (getSystemService("account") != null)) {
      paramContextMenu.add(0, 999, 0, 2131099665);
    }
  }
  
  public boolean onCreateOptionsMenu(Menu paramMenu)
  {
    return true;
  }
  
  public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
  {
    if ((paramInt == 4) && (this.adapter.chain.size() > 0))
    {
      FolderAdapter localFolderAdapter = this.adapter;
      if (this.adapter.chain.size() > 1) {}
      for (Entry localEntry = (Entry)this.adapter.chain.get(-2 + this.adapter.chain.size());; localEntry = null)
      {
        localFolderAdapter.changeFolder(localEntry);
        return true;
      }
    }
    return super.onKeyDown(paramInt, paramKeyEvent);
  }
  
  public boolean onMenuItemSelected(int paramInt, MenuItem paramMenuItem)
  {
    int i = paramMenuItem.getItemId();
    if (i == 999)
    {
      if (App.has_feature_gls)
      {
        final Object localObject = getSystemService("account");
        if (localObject != null)
        {
          this.wt = new Thread()
          {
            public void run()
            {
              try
              {
                Method[] arrayOfMethod = localObject.getClass().getMethods();
                for (int i = 0;; i++)
                {
                  int j = arrayOfMethod.length;
                  Method localMethod = null;
                  if (i < j)
                  {
                    if ("addAccount".equals(arrayOfMethod[i].getName())) {
                      localMethod = arrayOfMethod[i];
                    }
                  }
                  else
                  {
                    Object localObject1 = localObject;
                    Object[] arrayOfObject = new Object[7];
                    arrayOfObject[0] = "com.google";
                    arrayOfObject[1] = null;
                    arrayOfObject[2] = null;
                    arrayOfObject[3] = null;
                    arrayOfObject[4] = ActivityGDocsBrowser.this;
                    arrayOfObject[5] = null;
                    arrayOfObject[6] = null;
                    Object localObject2 = localMethod.invoke(localObject1, arrayOfObject);
                    String str = ((Bundle)localObject2.getClass().getMethod("getResult", new Class[0]).invoke(localObject2, new Object[0])).getString("authAccount");
                    if (str != null)
                    {
                      SharedPreferences.Editor localEditor = ActivityGDocsBrowser.this.prefs.edit();
                      localEditor.putString("gdocs_account", str);
                      localEditor.commit();
                      ActivityGDocsBrowser.this.init();
                    }
                    return;
                  }
                }
                return;
              }
              catch (Exception localException)
              {
                localException.printStackTrace();
                App.reportThrowable(localException);
              }
            }
          };
          this.wt.start();
        }
        return true;
      }
      showAccount(null);
      return true;
    }
    if ((i == 1) && (this.credentials != null)) {}
    for (int j = 0;; j++) {
      if (j < this.al.length)
      {
        if (this.al[j].equals(this.credentials[0])) {
          i = j + 1000;
        }
      }
      else
      {
        if (i < 1000) {
          break;
        }
        showAccount(this.al[(i - 1000)]);
        return true;
      }
    }
    return false;
  }
  
  public boolean onPrepareOptionsMenu(Menu paramMenu)
  {
    paramMenu.removeGroup(1);
    paramMenu.removeItem(1);
    paramMenu.add(0, 1, 0, 2131099666);
    paramMenu.removeGroup(2);
    paramMenu.removeItem(2);
    SubMenu localSubMenu = paramMenu.addSubMenu(0, 2, 0, 2131099664);
    if (this.al != null) {
      for (int i = 0; i < this.al.length; i++) {
        localSubMenu.add(0, i + 1000, 0, this.al[i]);
      }
    }
    if ((!App.has_feature_gls) || (getSystemService("account") != null)) {
      localSubMenu.add(0, 999, 0, 2131099665);
    }
    return true;
  }
  
  protected void onResume()
  {
    super.onResume();
    if ((this.al == null) || (requesting_credentials != 0))
    {
      showProgress(getResources().getString(2131099746));
      this.wt = new Thread()
      {
        public void run()
        {
          ActivityGDocsBrowser.this.init();
        }
      };
      this.wt.start();
    }
  }
  
  static class Entry
  {
    public Vector<String> folder_ids;
    public String id;
    public boolean loaded;
    public String title;
    public String type;
    public int type_rid;
    public String url;
    
    public Entry(String paramString1, String paramString2, String paramString3)
    {
      this.id = paramString1;
      this.type = paramString2;
      this.title = paramString3;
      if ("folder".equals(paramString2)) {}
      for (int i = 2130837541;; i = 2130837540)
      {
        this.type_rid = i;
        if (("folder".equals(paramString2)) && ("".equals(paramString1))) {
          this.type_rid = 2130837573;
        }
        return;
      }
    }
    
    public Entry(Element paramElement)
    {
      String str1 = XmlUtil.getFirstNodeValue(paramElement, "gd:resourceId");
      int i = str1.indexOf(":");
      this.id = str1.substring(i + 1);
      String str2;
      int j;
      label73:
      String str5;
      if (i >= 0)
      {
        str2 = str1.substring(0, i);
        this.type = str2;
        this.title = XmlUtil.getFirstNodeValue(paramElement, "title");
        if (!"folder".equals(this.type)) {
          break label303;
        }
        j = 2130837541;
        this.type_rid = j;
        Element localElement1 = XmlUtil.getFirstElement(paramElement, "content");
        if (localElement1 != null)
        {
          this.url = localElement1.getAttribute("src");
          str5 = localElement1.getAttribute("type");
          if (!"document".equals(this.type)) {
            break label310;
          }
          this.type_rid = 2130837539;
          this.url += "&format=pdf&exportFormat=pdf";
        }
      }
      for (;;)
      {
        NodeList localNodeList = paramElement.getElementsByTagName("link");
        int k = localNodeList.getLength();
        for (int m = 0; m < k; m++)
        {
          Element localElement2 = (Element)localNodeList.item(m);
          String str3 = localElement2.getAttribute("rel");
          if ((str3 != null) && (str3.indexOf("#parent") >= 0))
          {
            String str4 = localElement2.getAttribute("href");
            int n = str4.indexOf("folder%3A");
            if (n >= 0)
            {
              if (this.folder_ids == null) {
                this.folder_ids = new Vector();
              }
              this.folder_ids.add(str4.substring(n + 9));
            }
          }
        }
        str2 = "";
        break;
        label303:
        j = 2130837540;
        break label73;
        label310:
        if ("spreadsheet".equals(this.type))
        {
          this.type_rid = 2130837547;
          this.url += "&format=pdf&exportFormat=pdf";
        }
        else if ("presentation".equals(this.type))
        {
          this.type_rid = 2130837545;
          this.url += "&format=pdf&exportFormat=pdf";
        }
        else if ("pdf".equals(this.type))
        {
          this.type_rid = 2130837544;
          this.url += "&format=pdf&exportFormat=pdf";
        }
        else if (("file".equals(this.type)) && (str5 != null))
        {
          if ((str5.indexOf("image/jpeg") >= 0) || (str5.indexOf("image/png") >= 0)) {
            this.type_rid = 2130837543;
          } else if (str5.indexOf("application/pdf") >= 0) {
            this.type_rid = 2130837544;
          } else if ((str5.indexOf("application/msword") >= 0) || (str5.indexOf("application/vnd.openxmlformats-officedocument.wordprocessingml.document") >= 0)) {
            this.type_rid = 2130837539;
          } else if ((str5.indexOf("application/vnd.ms-excel") >= 0) || (str5.indexOf("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") >= 0)) {
            this.type_rid = 2130837547;
          } else if ((str5.indexOf("application/vnd.ms-powerpoint") >= 0) || (str5.indexOf("application/vnd.openxmlformats-officedocument.presentationml.presentation") >= 0)) {
            this.type_rid = 2130837545;
          } else {
            this.url = null;
          }
        }
        else
        {
          this.url = null;
        }
      }
    }
  }
  
  class FolderAdapter
    implements ListAdapter
  {
    private Vector<ActivityGDocsBrowser.Entry> chain = new Vector();
    private Vector<ActivityGDocsBrowser.Entry> entries = new Vector();
    private List<DataSetObserver> observers = null;
    
    public FolderAdapter()
    {
      changeFolder(null);
    }
    
    public boolean areAllItemsEnabled()
    {
      return true;
    }
    
    public void changeFolder(final ActivityGDocsBrowser.Entry paramEntry)
    {
      if ((paramEntry != null) && (!paramEntry.loaded))
      {
        ActivityGDocsBrowser.this.showProgress(ActivityGDocsBrowser.this.getResources().getString(2131099757));
        ActivityGDocsBrowser.access$202(ActivityGDocsBrowser.this, new Thread()
        {
          public void run()
          {
            if (ActivityGDocsBrowser.this.loadFolder(paramEntry.id)) {
              paramEntry.loaded = true;
            }
            while (ActivityGDocsBrowser.this.last_error != null)
            {
              ActivityGDocsBrowser.access$202(ActivityGDocsBrowser.this, null);
              ActivityGDocsBrowser.this.runOnUiThread(new Runnable()
              {
                public void run()
                {
                  ActivityGDocsBrowser.this.hideProgress();
                  if (ActivityGDocsBrowser.this.last_error == null)
                  {
                    ActivityGDocsBrowser.this.adapter.changeFolder(ActivityGDocsBrowser.FolderAdapter.1.this.val$folder);
                    return;
                  }
                  ActivityGDocsBrowser.this.displayLastError(new DialogInterface.OnClickListener()
                  {
                    public void onClick(DialogInterface paramAnonymous3DialogInterface, int paramAnonymous3Int) {}
                  });
                }
              });
              return;
            }
          }
        });
        ActivityGDocsBrowser.this.wt.start();
        return;
      }
      Vector localVector1;
      Vector localVector2;
      int i;
      ActivityGDocsBrowser.Entry localEntry;
      int j;
      if (paramEntry != null) {
        if ((this.chain.size() > 1) && (this.chain.get(-2 + this.chain.size()) == paramEntry))
        {
          this.chain.remove(-1 + this.chain.size());
          if (ActivityGDocsBrowser.this.credentials != null) {
            ActivityGDocsBrowser.this.setTitle(ActivityGDocsBrowser.this.getResources().getString(2131099701) + " - " + ActivityGDocsBrowser.this.credentials[0]);
          }
          localVector1 = new Vector();
          localVector2 = new Vector();
          i = 0;
          if (i >= ActivityGDocsBrowser.this.data.size()) {
            break label399;
          }
          localEntry = (ActivityGDocsBrowser.Entry)ActivityGDocsBrowser.this.data.get(i);
          if ((localEntry.folder_ids == null) || (paramEntry == null)) {
            break label351;
          }
          j = 0;
          label236:
          if (j >= localEntry.folder_ids.size()) {
            break label383;
          }
          if (((String)localEntry.folder_ids.get(j)).equals(paramEntry.id))
          {
            if (!"folder".equals(localEntry.type)) {
              break label341;
            }
            localVector1.add(localEntry);
          }
        }
      }
      for (;;)
      {
        j++;
        break label236;
        if ((this.chain.size() != 0) && (paramEntry == this.chain.lastElement())) {
          break;
        }
        this.chain.add(paramEntry);
        break;
        this.chain.clear();
        break;
        label341:
        localVector2.add(localEntry);
      }
      label351:
      if ((localEntry.folder_ids == null) && (paramEntry == null))
      {
        if (!"folder".equals(localEntry.type)) {
          break label389;
        }
        localVector1.add(localEntry);
      }
      for (;;)
      {
        label383:
        i++;
        break;
        label389:
        localVector2.add(localEntry);
      }
      label399:
      Comparator local2 = new Comparator()
      {
        public int compare(ActivityGDocsBrowser.Entry paramAnonymousEntry1, ActivityGDocsBrowser.Entry paramAnonymousEntry2)
        {
          return paramAnonymousEntry1.title.compareToIgnoreCase(paramAnonymousEntry2.title);
        }
      };
      Collections.sort(localVector1, local2);
      Collections.sort(localVector2, local2);
      this.entries.clear();
      if (paramEntry != null) {
        this.entries.add(new ActivityGDocsBrowser.Entry("", "folder", ".."));
      }
      this.entries.addAll(localVector1);
      this.entries.addAll(localVector2);
      fireOnChanged();
    }
    
    public void fireOnChanged()
    {
      if (this.observers != null)
      {
        int i = this.observers.size();
        for (int j = 0; j < i; j++) {
          ((DataSetObserver)this.observers.get(j)).onChanged();
        }
      }
    }
    
    public int getCount()
    {
      return this.entries.size();
    }
    
    public Object getItem(int paramInt)
    {
      return this.entries.get(paramInt);
    }
    
    public long getItemId(int paramInt)
    {
      return ((ActivityGDocsBrowser.Entry)this.entries.get(paramInt)).id.hashCode() << paramInt + 16;
    }
    
    public int getItemViewType(int paramInt)
    {
      return 0;
    }
    
    public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
    {
      LinearLayout localLinearLayout = (LinearLayout)paramView;
      ImageView localImageView;
      TextView localTextView;
      if (localLinearLayout == null)
      {
        localLinearLayout = new LinearLayout(ActivityGDocsBrowser.this);
        localLinearLayout.setOrientation(0);
        localImageView = new ImageView(ActivityGDocsBrowser.this);
        localLinearLayout.addView(localImageView, new ViewGroup.LayoutParams(-2, -2));
        localTextView = new TextView(ActivityGDocsBrowser.this);
        localTextView.setGravity(16);
        localTextView.setTextSize(1, 18.0F);
        localTextView.setSingleLine();
        localTextView.setTextColor(-4276546);
        localLinearLayout.addView(localTextView, new ViewGroup.LayoutParams(-2, -1));
      }
      for (;;)
      {
        int i = ((ActivityGDocsBrowser.Entry)this.entries.get(paramInt)).type_rid;
        if ((localImageView.getTag() == null) || (i != ((Integer)localImageView.getTag()).intValue()))
        {
          localImageView.setTag(Integer.valueOf(i));
          localImageView.setImageResource(i);
        }
        localLinearLayout.setTag(Integer.valueOf(paramInt));
        localTextView.setText(((ActivityGDocsBrowser.Entry)this.entries.get(paramInt)).title);
        return localLinearLayout;
        localImageView = (ImageView)localLinearLayout.getChildAt(0);
        localTextView = (TextView)localLinearLayout.getChildAt(1);
      }
    }
    
    public int getViewTypeCount()
    {
      return 1;
    }
    
    public boolean hasStableIds()
    {
      return false;
    }
    
    public boolean isEmpty()
    {
      return this.entries.size() == 0;
    }
    
    public boolean isEnabled(int paramInt)
    {
      return ("folder".equals(((ActivityGDocsBrowser.Entry)this.entries.get(paramInt)).type)) || (((ActivityGDocsBrowser.Entry)this.entries.get(paramInt)).url != null);
    }
    
    public void registerDataSetObserver(DataSetObserver paramDataSetObserver)
    {
      if (this.observers == null) {
        this.observers = new ArrayList();
      }
      if (!this.observers.contains(paramDataSetObserver)) {
        this.observers.add(paramDataSetObserver);
      }
    }
    
    public void unregisterDataSetObserver(DataSetObserver paramDataSetObserver)
    {
      if (this.observers == null) {
        return;
      }
      this.observers.remove(paramDataSetObserver);
    }
  }
}


/* Location:           C:\Users\Admin\Desktop\Decompiler\JAD\jd-gui-0.3.6.windows\classes_dex2jar.jar
 * Qualified Name:     com.dynamixsoftware.printershare.ActivityGDocsBrowser
 * JD-Core Version:    0.7.0.1
 */